﻿using Elasticsearch.Net;
using Google.Protobuf.Reflection;
using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LeafCore.Components.ElasticSearch
{
    public class ElasticSearchBaseService
    {
        protected readonly IElasticClient _elasticClient;

        public ElasticSearchBaseService(ElasticSearchOptions options)
        {
            ////多uris
            //var uris = new Uri[]
            //{
            //    new Uri(""),
            //    new Uri("")
            //};
            var pool = new StaticConnectionPool(options.Hosts);

            ////多node
            //var nodes = new Node[]
            //{
            //    new Node (new Uri("")),
            //    new Node (new Uri(""))
            //};
            ////链接池
            //var pool = new StaticConnectionPool(nodes);

            //注：nest默认字段名首字母小写，如果要设置为与Model中一致，在创建client时按如下设置。（强烈建议使用该设置，避免造成字段不一致）
            var settings = new ConnectionSettings(pool).DefaultFieldNameInferrer((name) => name);
            settings.BasicAuthentication(options.UserName, options.Password);

            _elasticClient = new ElasticClient(settings);
        }
    }
}
